﻿<%@ Page Title="店铺档案" Language="C#" MasterPageFile="~/master/m.master" %>
<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
<link href="../assets/css/shelf/base.css" rel="stylesheet">
<style type="text/css">
.system-box .right-side{width: 100%;}
#paramSet{display: none;}
#createYear{margin-left: 10px; padding: 5.5px 14px;}
.condition, .condition-title{position: relative; border-bottom: 1px solid #dfdfdd;}
.condition .form-control{padding: 2px 6px;}
#openSet{
	position: absolute;
	top: 50%;
	right: 10px;
	margin-top: -10px;
	cursor: pointer;
}
#openSet i{font-size: 16px;}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">
<div class="system-box">
	<div class="right-side">
		<div class="btns-container"></div>
		<div class="condition">
			<label>条件</label>
			<input type="text" class="form-control input-w160" id="search-keys" placeholder="在此输入节日名称" />
			<label>时间范围</label>
            <input type="text" class="form-control layer-date" 
            	readonly="readonly" placeholder="开始时间" id="search-start" />
			<label class="to">到</label>
			<input type="text" class="form-control layer-date" 
				readonly="readonly" placeholder="结束时间" id="search-end" />
			<span id="openSet">
				<span>生成日历</span>
				<i class="fa fa-angle-right"></i>
			</span>
		</div>
		
		<div id="paramSet" class="condition">
			<label>年份</label>
			<select id="Year" class="form-control input-w160"></select>
			<button class="btn btn-primary" type="button" id="createYear">生成</button>
		</div>
		
		<div class="right-content-box">
			<div class="ibox-content">
				<table class="footable table table-stripped table-list">
					<thead></thead>
					<tbody id="pageList"></tbody>
				</table>
			</div>
		</div>
		<div class="pageControl"></div>
	</div>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
<script src="../assets/js/plugins/layer/laydate/laydate.js"></script>
<script src="../assets/js/page/pageControl.js"></script>
<script src="../assets/js/page/rScroll.js"></script>
<script src="../assets/js/page/tableControl.js"></script>
<script type="application/javascript">
$('document').ready(function(){
	//模块ID
    var ModuleID = Y.getUrlParam("ModuleID");
    //当前页数
    var page = 1;
//  var maxYear = '';
	//获取按钮
	commonUtil.loadBtnList(ModuleID,function(){
		rScroll();
	});
	//初始化日期控件
	$('#search-start').val(new Date().getFullYear() + '-01-01');
	$('#search-end').val(new Date().getFullYear() + '-12-31');
	var searchstart = {
		elem: "#search-start",
		format: "YYYY-MM-DD",
		min: "2015-12-01",
		max: "2099-12-01",
		istime: false,
		istoday: false,
		choose: function (datas) {
			searchend.min = datas;
			searchend.start = datas
        }
    };
    var searchend = {
        elem: "#search-end",
        format: "YYYY-MM-DD",
        min: "2015-12-01",
        max: "2099-12-01",
        istime: false,
        istoday: false,
        choose: function (datas) {
            searchstart.max = datas
        }
    };
    laydate(searchstart);
    laydate(searchend);
	
	//绑定年份
	var gfy = new Date().getFullYear();
	for(var i = gfy; i < gfy + 10; i++){
		$('#Year').append('<option value="'+ i +'">'+ i +'</option>');	
	}
	
	//显示或隐藏日历生成
	$('#openSet').click(function(){
		if($(this).hasClass('clicked')){
			$(this).removeClass('clicked');
			$(this).find('i').attr('class','fa fa-angle-right');
			$('#paramSet').fadeOut();
		}else{
			$(this).addClass('clicked');
			$(this).find('i').attr('class','fa fa-angle-down');
			$('#paramSet').fadeIn();
		}
	})
	
	//生成按钮
//	var getMaxYear = function(){
//		Y.API3('Calendar','GetMaxMinYear',{},function(data){
//			if(data.Success == false){
//				swal(data.Message,'','error');
//			}else{
//				maxYear = data.MaxYear;
//			}
//		})
//	}
//	getMaxYear();
	
	$('#createYear').click(function(){
//		if(maxYear == '')
//			return false;
//		if(parseInt($('#Year').val()) > maxYear + 1){
//			swal('未生成' + (maxYear + 1) + '年');
//			return false;
//		}
		layer.msg('玩命加载中……', {icon: 16, shade: 0.5, time:0, maxWidth:200});
		Y.API2('Calendar','CreateCalendarDays',{Year: $('#Year').val()},function(data){
			layer.closeAll('dialog');
			if(data.Success == false){
				swal(data.Message,'','error');	
			}else{
				swal('已生成','','success');
			}
		})
	})
	
	//处理表头
    if($('.footable thead').children().size() == 0){
	    tableControl.initThead2('.footable',['年份','月份','周','星期','日期','农历','类型','节日名称','补货系数'])
    }
    
    var loadList = function(){
    	var keys = $('#search-keys').val().trim().replace(/'/g, '');
        pageControl.init('Calendar', 'GetCalendarList', {
            BeginDate: $('#search-start').val(),
            EndDate: $('#search-end').val(),
            Keys: keys,
            Page: page,
//          Size: 100,
            needLayer: true,
            alwaysCallBack: function () {
                $('#pageList').empty();
            }
        }, function (result) {
            page = result.page;
            var tBody = [];
            if (!Y.checkNull(result)) {
                if (result.data.Items.length > 0) {
                    result.data.Items.map(function (item, i) {
                        var tempTr = {
                            trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd'),
                            children: [
                                { tdText: (item.YearV || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
							    { tdText: (item.MonthV || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
							    { tdText: (item.Weekv || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
							    { tdText: (item.WeekDayNum || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
							    { tdText: (item.GregorianDay || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
							    { tdText: (item.LunarDay || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
							    { tdText: (item.DayType || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
							    { tdText: (item.TypeName || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
							    { tdText: (item.SuppleRate || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' }
                            ]
                        };
                        tBody.push(tempTr);
                    })
                }
                rScroll();
            }
            tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 7, null);
        });
    }
    loadList();
    
    $('.btns-container').on('click','#btn-search',function(){
    	loadList();
    })
})
</script>
</asp:Content>

